{
 "cells": [
  {
   "cell_type": "code",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-02-24T13:07:34.204379Z",
     "start_time": "2025-02-24T13:07:34.199361Z"
    }
   },
   "source": [
    "import time\n",
    "\n",
    "from sklearn.datasets import load_iris, fetch_20newsgroups, fetch_california_housing\n",
    "from sklearn.model_selection import train_test_split, GridSearchCV\n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "from sklearn.feature_extraction.text import TfidfVectorizer\n",
    "from sklearn.naive_bayes import MultinomialNB\n",
    "from sklearn.metrics import classification_report\n",
    "from sklearn.feature_extraction import DictVectorizer\n",
    "from sklearn.tree import DecisionTreeClassifier, export_graphviz\n",
    "from sklearn.ensemble import RandomForestClassifier\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.metrics import roc_auc_score"
   ],
   "outputs": [],
   "execution_count": 2
  },
  {
   "cell_type": "markdown",
   "source": [
    "load直接加载的内存的，数据集比较小，并不会保存到本地磁盘\n",
    "fetch数据集比较大，下载下来后会存在本地磁盘，下一次就不会再连接sklearn的服务器\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "获取特征值\n",
      "<class 'numpy.ndarray'>\n",
      "--------------------------------------------------\n",
      "(150, 4)\n"
     ]
    },
    {
     "data": {
      "text/plain": "array([[5.1, 3.5, 1.4, 0.2],\n       [4.9, 3. , 1.4, 0.2],\n       [4.7, 3.2, 1.3, 0.2],\n       [4.6, 3.1, 1.5, 0.2],\n       [5. , 3.6, 1.4, 0.2],\n       [5.4, 3.9, 1.7, 0.4],\n       [4.6, 3.4, 1.4, 0.3],\n       [5. , 3.4, 1.5, 0.2],\n       [4.4, 2.9, 1.4, 0.2],\n       [4.9, 3.1, 1.5, 0.1],\n       [5.4, 3.7, 1.5, 0.2],\n       [4.8, 3.4, 1.6, 0.2],\n       [4.8, 3. , 1.4, 0.1],\n       [4.3, 3. , 1.1, 0.1],\n       [5.8, 4. , 1.2, 0.2],\n       [5.7, 4.4, 1.5, 0.4],\n       [5.4, 3.9, 1.3, 0.4],\n       [5.1, 3.5, 1.4, 0.3],\n       [5.7, 3.8, 1.7, 0.3],\n       [5.1, 3.8, 1.5, 0.3],\n       [5.4, 3.4, 1.7, 0.2],\n       [5.1, 3.7, 1.5, 0.4],\n       [4.6, 3.6, 1. , 0.2],\n       [5.1, 3.3, 1.7, 0.5],\n       [4.8, 3.4, 1.9, 0.2],\n       [5. , 3. , 1.6, 0.2],\n       [5. , 3.4, 1.6, 0.4],\n       [5.2, 3.5, 1.5, 0.2],\n       [5.2, 3.4, 1.4, 0.2],\n       [4.7, 3.2, 1.6, 0.2],\n       [4.8, 3.1, 1.6, 0.2],\n       [5.4, 3.4, 1.5, 0.4],\n       [5.2, 4.1, 1.5, 0.1],\n       [5.5, 4.2, 1.4, 0.2],\n       [4.9, 3.1, 1.5, 0.2],\n       [5. , 3.2, 1.2, 0.2],\n       [5.5, 3.5, 1.3, 0.2],\n       [4.9, 3.6, 1.4, 0.1],\n       [4.4, 3. , 1.3, 0.2],\n       [5.1, 3.4, 1.5, 0.2],\n       [5. , 3.5, 1.3, 0.3],\n       [4.5, 2.3, 1.3, 0.3],\n       [4.4, 3.2, 1.3, 0.2],\n       [5. , 3.5, 1.6, 0.6],\n       [5.1, 3.8, 1.9, 0.4],\n       [4.8, 3. , 1.4, 0.3],\n       [5.1, 3.8, 1.6, 0.2],\n       [4.6, 3.2, 1.4, 0.2],\n       [5.3, 3.7, 1.5, 0.2],\n       [5. , 3.3, 1.4, 0.2],\n       [7. , 3.2, 4.7, 1.4],\n       [6.4, 3.2, 4.5, 1.5],\n       [6.9, 3.1, 4.9, 1.5],\n       [5.5, 2.3, 4. , 1.3],\n       [6.5, 2.8, 4.6, 1.5],\n       [5.7, 2.8, 4.5, 1.3],\n       [6.3, 3.3, 4.7, 1.6],\n       [4.9, 2.4, 3.3, 1. ],\n       [6.6, 2.9, 4.6, 1.3],\n       [5.2, 2.7, 3.9, 1.4],\n       [5. , 2. , 3.5, 1. ],\n       [5.9, 3. , 4.2, 1.5],\n       [6. , 2.2, 4. , 1. ],\n       [6.1, 2.9, 4.7, 1.4],\n       [5.6, 2.9, 3.6, 1.3],\n       [6.7, 3.1, 4.4, 1.4],\n       [5.6, 3. , 4.5, 1.5],\n       [5.8, 2.7, 4.1, 1. ],\n       [6.2, 2.2, 4.5, 1.5],\n       [5.6, 2.5, 3.9, 1.1],\n       [5.9, 3.2, 4.8, 1.8],\n       [6.1, 2.8, 4. , 1.3],\n       [6.3, 2.5, 4.9, 1.5],\n       [6.1, 2.8, 4.7, 1.2],\n       [6.4, 2.9, 4.3, 1.3],\n       [6.6, 3. , 4.4, 1.4],\n       [6.8, 2.8, 4.8, 1.4],\n       [6.7, 3. , 5. , 1.7],\n       [6. , 2.9, 4.5, 1.5],\n       [5.7, 2.6, 3.5, 1. ],\n       [5.5, 2.4, 3.8, 1.1],\n       [5.5, 2.4, 3.7, 1. ],\n       [5.8, 2.7, 3.9, 1.2],\n       [6. , 2.7, 5.1, 1.6],\n       [5.4, 3. , 4.5, 1.5],\n       [6. , 3.4, 4.5, 1.6],\n       [6.7, 3.1, 4.7, 1.5],\n       [6.3, 2.3, 4.4, 1.3],\n       [5.6, 3. , 4.1, 1.3],\n       [5.5, 2.5, 4. , 1.3],\n       [5.5, 2.6, 4.4, 1.2],\n       [6.1, 3. , 4.6, 1.4],\n       [5.8, 2.6, 4. , 1.2],\n       [5. , 2.3, 3.3, 1. ],\n       [5.6, 2.7, 4.2, 1.3],\n       [5.7, 3. , 4.2, 1.2],\n       [5.7, 2.9, 4.2, 1.3],\n       [6.2, 2.9, 4.3, 1.3],\n       [5.1, 2.5, 3. , 1.1],\n       [5.7, 2.8, 4.1, 1.3],\n       [6.3, 3.3, 6. , 2.5],\n       [5.8, 2.7, 5.1, 1.9],\n       [7.1, 3. , 5.9, 2.1],\n       [6.3, 2.9, 5.6, 1.8],\n       [6.5, 3. , 5.8, 2.2],\n       [7.6, 3. , 6.6, 2.1],\n       [4.9, 2.5, 4.5, 1.7],\n       [7.3, 2.9, 6.3, 1.8],\n       [6.7, 2.5, 5.8, 1.8],\n       [7.2, 3.6, 6.1, 2.5],\n       [6.5, 3.2, 5.1, 2. ],\n       [6.4, 2.7, 5.3, 1.9],\n       [6.8, 3. , 5.5, 2.1],\n       [5.7, 2.5, 5. , 2. ],\n       [5.8, 2.8, 5.1, 2.4],\n       [6.4, 3.2, 5.3, 2.3],\n       [6.5, 3. , 5.5, 1.8],\n       [7.7, 3.8, 6.7, 2.2],\n       [7.7, 2.6, 6.9, 2.3],\n       [6. , 2.2, 5. , 1.5],\n       [6.9, 3.2, 5.7, 2.3],\n       [5.6, 2.8, 4.9, 2. ],\n       [7.7, 2.8, 6.7, 2. ],\n       [6.3, 2.7, 4.9, 1.8],\n       [6.7, 3.3, 5.7, 2.1],\n       [7.2, 3.2, 6. , 1.8],\n       [6.2, 2.8, 4.8, 1.8],\n       [6.1, 3. , 4.9, 1.8],\n       [6.4, 2.8, 5.6, 2.1],\n       [7.2, 3. , 5.8, 1.6],\n       [7.4, 2.8, 6.1, 1.9],\n       [7.9, 3.8, 6.4, 2. ],\n       [6.4, 2.8, 5.6, 2.2],\n       [6.3, 2.8, 5.1, 1.5],\n       [6.1, 2.6, 5.6, 1.4],\n       [7.7, 3. , 6.1, 2.3],\n       [6.3, 3.4, 5.6, 2.4],\n       [6.4, 3.1, 5.5, 1.8],\n       [6. , 3. , 4.8, 1.8],\n       [6.9, 3.1, 5.4, 2.1],\n       [6.7, 3.1, 5.6, 2.4],\n       [6.9, 3.1, 5.1, 2.3],\n       [5.8, 2.7, 5.1, 1.9],\n       [6.8, 3.2, 5.9, 2.3],\n       [6.7, 3.3, 5.7, 2.5],\n       [6.7, 3. , 5.2, 2.3],\n       [6.3, 2.5, 5. , 1.9],\n       [6.5, 3. , 5.2, 2. ],\n       [6.2, 3.4, 5.4, 2.3],\n       [5.9, 3. , 5.1, 1.8]])"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#鸢尾花数据集，查看特征，目标，样本量\n",
    "\n",
    "li = load_iris()\n",
    "\n",
    "print(\"获取特征值\")\n",
    "print(type(li.data))\n",
    "print('-' * 50)\n",
    "print(li.data.shape) # 150个样本，4个特征,一般看shape\n",
    "li.data"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T03:24:27.811108400Z",
     "start_time": "2024-07-11T03:24:27.759095600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "目标值\n",
      "[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
      " 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
      " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2\n",
      " 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n",
      " 2 2]\n",
      "--------------------------------------------------\n",
      ".. _iris_dataset:\n",
      "\n",
      "Iris plants dataset\n",
      "--------------------\n",
      "\n",
      "**Data Set Characteristics:**\n",
      "\n",
      ":Number of Instances: 150 (50 in each of three classes)\n",
      ":Number of Attributes: 4 numeric, predictive attributes and the class\n",
      ":Attribute Information:\n",
      "    - sepal length in cm\n",
      "    - sepal width in cm\n",
      "    - petal length in cm\n",
      "    - petal width in cm\n",
      "    - class:\n",
      "            - Iris-Setosa\n",
      "            - Iris-Versicolour\n",
      "            - Iris-Virginica\n",
      "\n",
      ":Summary Statistics:\n",
      "\n",
      "============== ==== ==== ======= ===== ====================\n",
      "                Min  Max   Mean    SD   Class Correlation\n",
      "============== ==== ==== ======= ===== ====================\n",
      "sepal length:   4.3  7.9   5.84   0.83    0.7826\n",
      "sepal width:    2.0  4.4   3.05   0.43   -0.4194\n",
      "petal length:   1.0  6.9   3.76   1.76    0.9490  (high!)\n",
      "petal width:    0.1  2.5   1.20   0.76    0.9565  (high!)\n",
      "============== ==== ==== ======= ===== ====================\n",
      "\n",
      ":Missing Attribute Values: None\n",
      ":Class Distribution: 33.3% for each of 3 classes.\n",
      ":Creator: R.A. Fisher\n",
      ":Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)\n",
      ":Date: July, 1988\n",
      "\n",
      "The famous Iris database, first used by Sir R.A. Fisher. The dataset is taken\n",
      "from Fisher's paper. Note that it's the same as in R, but not as in the UCI\n",
      "Machine Learning Repository, which has two wrong data points.\n",
      "\n",
      "This is perhaps the best known database to be found in the\n",
      "pattern recognition literature.  Fisher's paper is a classic in the field and\n",
      "is referenced frequently to this day.  (See Duda & Hart, for example.)  The\n",
      "data set contains 3 classes of 50 instances each, where each class refers to a\n",
      "type of iris plant.  One class is linearly separable from the other 2; the\n",
      "latter are NOT linearly separable from each other.\n",
      "\n",
      "|details-start|\n",
      "**References**\n",
      "|details-split|\n",
      "\n",
      "- Fisher, R.A. \"The use of multiple measurements in taxonomic problems\"\n",
      "  Annual Eugenics, 7, Part II, 179-188 (1936); also in \"Contributions to\n",
      "  Mathematical Statistics\" (John Wiley, NY, 1950).\n",
      "- Duda, R.O., & Hart, P.E. (1973) Pattern Classification and Scene Analysis.\n",
      "  (Q327.D83) John Wiley & Sons.  ISBN 0-471-22361-1.  See page 218.\n",
      "- Dasarathy, B.V. (1980) \"Nosing Around the Neighborhood: A New System\n",
      "  Structure and Classification Rule for Recognition in Partially Exposed\n",
      "  Environments\".  IEEE Transactions on Pattern Analysis and Machine\n",
      "  Intelligence, Vol. PAMI-2, No. 1, 67-71.\n",
      "- Gates, G.W. (1972) \"The Reduced Nearest Neighbor Rule\".  IEEE Transactions\n",
      "  on Information Theory, May 1972, 431-433.\n",
      "- See also: 1988 MLC Proceedings, 54-64.  Cheeseman et al\"s AUTOCLASS II\n",
      "  conceptual clustering system finds 3 classes in the data.\n",
      "- Many, many more ...\n",
      "\n",
      "|details-end|\n",
      "\n",
      "--------------------------------------------------\n",
      "['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']\n",
      "--------------------------------------------------\n",
      "['setosa' 'versicolor' 'virginica']\n"
     ]
    }
   ],
   "source": [
    "print(\"目标值\")\n",
    "print(li.target)\n",
    "print('-' * 50)\n",
    "print(li.DESCR)\n",
    "print('-' * 50)\n",
    "print(li.feature_names)  # 重点,特征名字\n",
    "print('-' * 50)\n",
    "print(li.target_names) # 目标名字"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-11T03:28:51.209751200Z",
     "start_time": "2024-07-11T03:28:51.193577800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练集特征值和目标值： [[6.5 2.8 4.6 1.5]\n",
      " [6.7 2.5 5.8 1.8]\n",
      " [6.8 3.  5.5 2.1]\n",
      " [5.1 3.5 1.4 0.3]\n",
      " [6.  2.2 5.  1.5]\n",
      " [6.3 2.9 5.6 1.8]\n",
      " [6.6 2.9 4.6 1.3]\n",
      " [7.7 2.6 6.9 2.3]\n",
      " [5.7 3.8 1.7 0.3]\n",
      " [5.  3.6 1.4 0.2]\n",
      " [4.8 3.  1.4 0.3]\n",
      " [5.2 2.7 3.9 1.4]\n",
      " [5.1 3.4 1.5 0.2]\n",
      " [5.5 3.5 1.3 0.2]\n",
      " [7.7 3.8 6.7 2.2]\n",
      " [6.9 3.1 5.4 2.1]\n",
      " [7.3 2.9 6.3 1.8]\n",
      " [6.4 2.8 5.6 2.2]\n",
      " [6.2 2.8 4.8 1.8]\n",
      " [6.  3.4 4.5 1.6]\n",
      " [7.7 2.8 6.7 2. ]\n",
      " [5.7 3.  4.2 1.2]\n",
      " [4.8 3.4 1.6 0.2]\n",
      " [5.7 2.5 5.  2. ]\n",
      " [6.3 2.7 4.9 1.8]\n",
      " [4.8 3.  1.4 0.1]\n",
      " [4.7 3.2 1.3 0.2]\n",
      " [6.5 3.  5.8 2.2]\n",
      " [4.6 3.4 1.4 0.3]\n",
      " [6.1 3.  4.9 1.8]\n",
      " [6.5 3.2 5.1 2. ]\n",
      " [6.7 3.1 4.4 1.4]\n",
      " [5.7 2.8 4.5 1.3]\n",
      " [6.7 3.3 5.7 2.5]\n",
      " [6.  3.  4.8 1.8]\n",
      " [5.1 3.8 1.6 0.2]\n",
      " [6.  2.2 4.  1. ]\n",
      " [6.4 2.9 4.3 1.3]\n",
      " [6.5 3.  5.5 1.8]\n",
      " [5.  2.3 3.3 1. ]\n",
      " [6.3 3.3 6.  2.5]\n",
      " [5.5 2.5 4.  1.3]\n",
      " [5.4 3.7 1.5 0.2]\n",
      " [4.9 3.1 1.5 0.2]\n",
      " [5.2 4.1 1.5 0.1]\n",
      " [6.7 3.3 5.7 2.1]\n",
      " [4.4 3.  1.3 0.2]\n",
      " [6.  2.7 5.1 1.6]\n",
      " [6.4 2.7 5.3 1.9]\n",
      " [5.9 3.  5.1 1.8]\n",
      " [5.2 3.5 1.5 0.2]\n",
      " [5.1 3.3 1.7 0.5]\n",
      " [5.8 2.7 4.1 1. ]\n",
      " [4.9 3.1 1.5 0.1]\n",
      " [7.4 2.8 6.1 1.9]\n",
      " [6.2 2.9 4.3 1.3]\n",
      " [7.6 3.  6.6 2.1]\n",
      " [6.7 3.  5.2 2.3]\n",
      " [6.3 2.3 4.4 1.3]\n",
      " [6.2 3.4 5.4 2.3]\n",
      " [7.2 3.6 6.1 2.5]\n",
      " [5.6 2.9 3.6 1.3]\n",
      " [5.7 4.4 1.5 0.4]\n",
      " [5.8 2.7 3.9 1.2]\n",
      " [4.5 2.3 1.3 0.3]\n",
      " [5.5 2.4 3.8 1.1]\n",
      " [6.9 3.1 4.9 1.5]\n",
      " [5.  3.4 1.6 0.4]\n",
      " [6.8 2.8 4.8 1.4]\n",
      " [5.  3.5 1.6 0.6]\n",
      " [4.8 3.4 1.9 0.2]\n",
      " [6.3 3.4 5.6 2.4]\n",
      " [5.6 2.8 4.9 2. ]\n",
      " [6.8 3.2 5.9 2.3]\n",
      " [5.  3.3 1.4 0.2]\n",
      " [5.1 3.7 1.5 0.4]\n",
      " [5.9 3.2 4.8 1.8]\n",
      " [4.6 3.1 1.5 0.2]\n",
      " [5.8 2.7 5.1 1.9]\n",
      " [4.8 3.1 1.6 0.2]\n",
      " [6.5 3.  5.2 2. ]\n",
      " [4.9 2.5 4.5 1.7]\n",
      " [4.6 3.2 1.4 0.2]\n",
      " [6.4 3.2 5.3 2.3]\n",
      " [4.3 3.  1.1 0.1]\n",
      " [5.6 3.  4.1 1.3]\n",
      " [4.4 2.9 1.4 0.2]\n",
      " [5.5 2.4 3.7 1. ]\n",
      " [5.  2.  3.5 1. ]\n",
      " [5.1 3.5 1.4 0.2]\n",
      " [4.9 3.  1.4 0.2]\n",
      " [4.9 2.4 3.3 1. ]\n",
      " [4.6 3.6 1.  0.2]\n",
      " [5.9 3.  4.2 1.5]\n",
      " [6.1 2.9 4.7 1.4]\n",
      " [5.  3.4 1.5 0.2]\n",
      " [6.7 3.1 4.7 1.5]\n",
      " [5.7 2.9 4.2 1.3]\n",
      " [6.2 2.2 4.5 1.5]\n",
      " [7.  3.2 4.7 1.4]\n",
      " [5.8 2.7 5.1 1.9]\n",
      " [5.4 3.4 1.7 0.2]\n",
      " [5.  3.  1.6 0.2]\n",
      " [6.1 2.6 5.6 1.4]\n",
      " [6.1 2.8 4.  1.3]\n",
      " [7.2 3.  5.8 1.6]\n",
      " [5.7 2.6 3.5 1. ]\n",
      " [6.3 2.8 5.1 1.5]\n",
      " [6.4 3.1 5.5 1.8]\n",
      " [6.3 2.5 4.9 1.5]\n",
      " [6.7 3.1 5.6 2.4]\n",
      " [4.9 3.6 1.4 0.1]] [1 2 2 0 2 2 1 2 0 0 0 1 0 0 2 2 2 2 2 1 2 1 0 2 2 0 0 2 0 2 2 1 1 2 2 0 1\n",
      " 1 2 1 2 1 0 0 0 2 0 1 2 2 0 0 1 0 2 1 2 2 1 2 2 1 0 1 0 1 1 0 1 0 0 2 2 2\n",
      " 0 0 1 0 2 0 2 2 0 2 0 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 2 0 0 2 1 2 1 2 2 1 2\n",
      " 0]\n",
      "训练集特征值shape (112, 4)\n",
      "--------------------------------------------------\n",
      "测试集特征值和目标值： [[5.8 4.  1.2 0.2]\n",
      " [5.1 2.5 3.  1.1]\n",
      " [6.6 3.  4.4 1.4]\n",
      " [5.4 3.9 1.3 0.4]\n",
      " [7.9 3.8 6.4 2. ]\n",
      " [6.3 3.3 4.7 1.6]\n",
      " [6.9 3.1 5.1 2.3]\n",
      " [5.1 3.8 1.9 0.4]\n",
      " [4.7 3.2 1.6 0.2]\n",
      " [6.9 3.2 5.7 2.3]\n",
      " [5.6 2.7 4.2 1.3]\n",
      " [5.4 3.9 1.7 0.4]\n",
      " [7.1 3.  5.9 2.1]\n",
      " [6.4 3.2 4.5 1.5]\n",
      " [6.  2.9 4.5 1.5]\n",
      " [4.4 3.2 1.3 0.2]\n",
      " [5.8 2.6 4.  1.2]\n",
      " [5.6 3.  4.5 1.5]\n",
      " [5.4 3.4 1.5 0.4]\n",
      " [5.  3.2 1.2 0.2]\n",
      " [5.5 2.6 4.4 1.2]\n",
      " [5.4 3.  4.5 1.5]\n",
      " [6.7 3.  5.  1.7]\n",
      " [5.  3.5 1.3 0.3]\n",
      " [7.2 3.2 6.  1.8]\n",
      " [5.7 2.8 4.1 1.3]\n",
      " [5.5 4.2 1.4 0.2]\n",
      " [5.1 3.8 1.5 0.3]\n",
      " [6.1 2.8 4.7 1.2]\n",
      " [6.3 2.5 5.  1.9]\n",
      " [6.1 3.  4.6 1.4]\n",
      " [7.7 3.  6.1 2.3]\n",
      " [5.6 2.5 3.9 1.1]\n",
      " [6.4 2.8 5.6 2.1]\n",
      " [5.8 2.8 5.1 2.4]\n",
      " [5.3 3.7 1.5 0.2]\n",
      " [5.5 2.3 4.  1.3]\n",
      " [5.2 3.4 1.4 0.2]] [0 1 1 0 2 1 2 0 0 2 1 0 2 1 1 0 1 1 0 0 1 1 1 0 2 1 0 0 1 2 1 2 1 2 2 0 1\n",
      " 0]\n",
      "测试集特征值shape (38, 4)\n"
     ]
    }
   ],
   "source": [
    "# 注意返回值, 训练集 train  x_train, y_train        测试集  test   x_test, y_test，顺序千万别搞错了\n",
    "# 默认是乱序的,random_state为了确保两次的随机策略一致，就会得到相同的随机数据，往往会带上\n",
    "x_train, x_test, y_train, y_test = train_test_split(li.data, li.target, test_size=0.25, random_state=1)\n",
    "\n",
    "print(\"训练集特征值和目标值：\", x_train, y_train)\n",
    "print(\"训练集特征值shape\", x_train.shape)\n",
    "print('-'*50)\n",
    "print(\"测试集特征值和目标值：\", x_test, y_test)\n",
    "print(\"测试集特征值shape\", x_test.shape)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T03:31:42.045991Z",
     "start_time": "2024-07-11T03:31:42.038015900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "data": {
      "text/plain": "37.5"
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "150*0.25"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-17T02:41:10.207726200Z",
     "start_time": "2024-04-17T02:41:09.839935300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第一个样本\n",
      "From: Mamatha Devineni Ratnam <mr47+@andrew.cmu.edu>\n",
      "Subject: Pens fans reactions\n",
      "Organization: Post Office, Carnegie Mellon, Pittsburgh, PA\n",
      "Lines: 12\n",
      "NNTP-Posting-Host: po4.andrew.cmu.edu\n",
      "\n",
      "\n",
      "\n",
      "I am sure some bashers of Pens fans are pretty confused about the lack\n",
      "of any kind of posts about the recent Pens massacre of the Devils. Actually,\n",
      "I am  bit puzzled too and a bit relieved. However, I am going to put an end\n",
      "to non-PIttsburghers' relief with a bit of praise for the Pens. Man, they\n",
      "are killing those Devils worse than I thought. Jagr just showed you why\n",
      "he is much better than his regular season stats. He is also a lot\n",
      "fo fun to watch in the playoffs. Bowman should let JAgr have a lot of\n",
      "fun in the next couple of games since the Pens are going to beat the pulp out of Jersey anyway. I was very disappointed not to see the Islanders lose the final\n",
      "regular season game.          PENS RULE!!!\n",
      "\n",
      "\n",
      "特征类型\n",
      "<class 'list'>\n",
      "--------------------------------------------------\n",
      "[10  3 17  3  4 12  4 10 10 19 19 11 19 13  0]\n",
      "['alt.atheism',\n",
      " 'comp.graphics',\n",
      " 'comp.os.ms-windows.misc',\n",
      " 'comp.sys.ibm.pc.hardware',\n",
      " 'comp.sys.mac.hardware',\n",
      " 'comp.windows.x',\n",
      " 'misc.forsale',\n",
      " 'rec.autos',\n",
      " 'rec.motorcycles',\n",
      " 'rec.sport.baseball',\n",
      " 'rec.sport.hockey',\n",
      " 'sci.crypt',\n",
      " 'sci.electronics',\n",
      " 'sci.med',\n",
      " 'sci.space',\n",
      " 'soc.religion.christian',\n",
      " 'talk.politics.guns',\n",
      " 'talk.politics.mideast',\n",
      " 'talk.politics.misc',\n",
      " 'talk.religion.misc']\n"
     ]
    }
   ],
   "source": [
    "# 下面是比较大的数据，需要下载一会，20类新闻\n",
    "#subset代表下载的数据集类型，默认是train，只有训练集\n",
    "news = fetch_20newsgroups(subset='all', data_home='data')\n",
    "# print(news.feature_names)  #这个数据集是没有的，因为没有特征，只有文本数据\n",
    "# print(news.DESCR)\n",
    "print('第一个样本')\n",
    "print(news.data[0])\n",
    "print('特征类型')\n",
    "print(type(news.data))\n",
    "print('-' * 50)\n",
    "print(news.target[0:15])\n",
    "from pprint import pprint\n",
    "pprint(list(news.target_names))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T03:37:25.363292600Z",
     "start_time": "2024-07-11T03:37:25.057661Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------------------------------------\n",
      "18846\n",
      "新闻所有的标签\n",
      "[10  3 17 ...  3  1  7]\n",
      "--------------------------------------------------\n",
      "0 19\n"
     ]
    }
   ],
   "source": [
    "print('-' * 50)\n",
    "print(len(news.data))\n",
    "print('新闻所有的标签')\n",
    "print(news.target)\n",
    "print('-' * 50)\n",
    "print(min(news.target), max(news.target))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-04-17T02:41:10.504554500Z",
     "start_time": "2024-04-17T02:41:10.431598700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [],
   "source": [
    "#因为新版本sklearn去掉了 这个数据集，不再讲解\n",
    "# 接着来看回归的数据,是波士顿房价\n",
    "# lb = load_boston()\n",
    "#\n",
    "# print(\"获取特征值\")\n",
    "# print(lb.data[0])  #第一个样本特征值\n",
    "# print(lb.data.shape)\n",
    "# print('-' * 50)\n",
    "# print(\"目标值\")\n",
    "# print(lb.target)\n",
    "# print('-' * 50)\n",
    "# print(lb.DESCR)\n",
    "# print('-' * 50)\n",
    "# print(lb.feature_names)\n",
    "# print('-' * 50)\n",
    "# 回归问题没这个,打印这个会报错\n",
    "# print(lb.target_names)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-17T02:41:10.526546700Z",
     "start_time": "2024-04-17T02:41:10.450585500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "获取特征值\n",
      "[   8.3252       41.            6.98412698    1.02380952  322.\n",
      "    2.55555556   37.88       -122.23      ]\n",
      "样本的形状\n",
      "(20640, 8)\n",
      "--------------------------------------------------\n"
     ]
    }
   ],
   "source": [
    "house=fetch_california_housing(data_home='data')\n",
    "print(\"获取特征值\")\n",
    "print(house.data[0])  #第一个样本特征值\n",
    "print('样本的形状')\n",
    "print(house.data.shape)\n",
    "print('-' * 50)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T03:40:08.556725Z",
     "start_time": "2024-07-11T03:40:08.481437600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "目标值\n",
      "[4.526 3.585 3.521 ... 0.923 0.847 0.894]\n",
      "--------------------------------------------------\n",
      ".. _california_housing_dataset:\n",
      "\n",
      "California Housing dataset\n",
      "--------------------------\n",
      "\n",
      "**Data Set Characteristics:**\n",
      "\n",
      ":Number of Instances: 20640\n",
      "\n",
      ":Number of Attributes: 8 numeric, predictive attributes and the target\n",
      "\n",
      ":Attribute Information:\n",
      "    - MedInc        median income in block group\n",
      "    - HouseAge      median house age in block group\n",
      "    - AveRooms      average number of rooms per household\n",
      "    - AveBedrms     average number of bedrooms per household\n",
      "    - Population    block group population\n",
      "    - AveOccup      average number of household members\n",
      "    - Latitude      block group latitude\n",
      "    - Longitude     block group longitude\n",
      "\n",
      ":Missing Attribute Values: None\n",
      "\n",
      "This dataset was obtained from the StatLib repository.\n",
      "https://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.html\n",
      "\n",
      "The target variable is the median house value for California districts,\n",
      "expressed in hundreds of thousands of dollars ($100,000).\n",
      "\n",
      "This dataset was derived from the 1990 U.S. census, using one row per census\n",
      "block group. A block group is the smallest geographical unit for which the U.S.\n",
      "Census Bureau publishes sample data (a block group typically has a population\n",
      "of 600 to 3,000 people).\n",
      "\n",
      "A household is a group of people residing within a home. Since the average\n",
      "number of rooms and bedrooms in this dataset are provided per household, these\n",
      "columns may take surprisingly large values for block groups with few households\n",
      "and many empty houses, such as vacation resorts.\n",
      "\n",
      "It can be downloaded/loaded using the\n",
      ":func:`sklearn.datasets.fetch_california_housing` function.\n",
      "\n",
      ".. topic:: References\n",
      "\n",
      "    - Pace, R. Kelley and Ronald Barry, Sparse Spatial Autoregressions,\n",
      "      Statistics and Probability Letters, 33 (1997) 291-297\n",
      "\n",
      "--------------------------------------------------\n",
      "['MedInc', 'HouseAge', 'AveRooms', 'AveBedrms', 'Population', 'AveOccup', 'Latitude', 'Longitude']\n",
      "--------------------------------------------------\n"
     ]
    }
   ],
   "source": [
    "print(\"目标值\")\n",
    "print(house.target)\n",
    "print('-' * 50)\n",
    "print(house.DESCR)\n",
    "print('-' * 50)\n",
    "print(house.feature_names)\n",
    "print('-' * 50)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-11T03:40:11.697556800Z",
     "start_time": "2024-07-11T03:40:11.684709300Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 2 分类估计器"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "outputs": [
    {
     "data": {
      "text/plain": "20.518284528683193"
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sqrt(15*15+14*14)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-17T02:41:10.593503700Z",
     "start_time": "2024-04-17T02:41:10.559525100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   row_id       x       y  accuracy    time    place_id\n",
      "0       0  0.7941  9.0809        54  470702  8523065625\n",
      "1       1  5.9567  4.7968        13  186555  1757726713\n",
      "2       2  8.3078  7.0407        74  322648  1137537235\n",
      "3       3  7.3665  2.5165        65  704587  6567393236\n",
      "4       4  4.0961  1.1307        31  472130  7440663949\n",
      "5       5  3.8099  1.9586        75  178065  6289802927\n",
      "6       6  6.3336  4.3720        13  666829  9931249544\n",
      "7       7  5.7409  6.7697        85  369002  5662813655\n",
      "8       8  4.3114  6.9410         3  166384  8471780938\n",
      "9       9  6.3414  0.0758        65  400060  1253803156\n",
      "(29118021, 6)\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 29118021 entries, 0 to 29118020\n",
      "Data columns (total 6 columns):\n",
      " #   Column    Dtype  \n",
      "---  ------    -----  \n",
      " 0   row_id    int64  \n",
      " 1   x         float64\n",
      " 2   y         float64\n",
      " 3   accuracy  int64  \n",
      " 4   time      int64  \n",
      " 5   place_id  int64  \n",
      "dtypes: float64(2), int64(4)\n",
      "memory usage: 1.3 GB\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "# K近邻\n",
    "\"\"\"\n",
    "K-近邻预测用户签到位置\n",
    ":return:None\n",
    "\"\"\"\n",
    "# 读取数据\n",
    "data = pd.read_csv(\"./data/FBlocation/train.csv\")\n",
    "\n",
    "print(data.head(10))\n",
    "print(data.shape)\n",
    "print(data.info())\n",
    "# 处理数据\n",
    "# 1、缩小数据,查询数据,为了减少计算时间\n",
    "data = data.query(\"x > 1.0 &  x < 1.25 & y > 2.5 & y < 2.75\")\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T06:44:34.621753400Z",
     "start_time": "2024-07-11T06:44:14.050566900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "data": {
      "text/plain": "(17710, 6)"
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-11T06:44:54.560604100Z",
     "start_time": "2024-07-11T06:44:54.547604400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "outputs": [
    {
     "data": {
      "text/plain": "             row_id             x             y      accuracy           time  \\\ncount  1.771000e+04  17710.000000  17710.000000  17710.000000   17710.000000   \nmean   1.450569e+07      1.122538      2.632309     82.482101  397551.263128   \nstd    8.353805e+06      0.077086      0.070144    113.613227  234601.097883   \nmin    6.000000e+02      1.000100      2.500100      1.000000     119.000000   \n25%    7.327816e+06      1.049200      2.573800     25.000000  174069.750000   \n50%    1.443071e+07      1.123300      2.642300     62.000000  403387.500000   \n75%    2.163463e+07      1.190500      2.687800     75.000000  602111.750000   \nmax    2.911215e+07      1.249900      2.749900   1004.000000  786218.000000   \n\n           place_id  \ncount  1.771000e+04  \nmean   5.129895e+09  \nstd    2.357399e+09  \nmin    1.012024e+09  \n25%    3.312464e+09  \n50%    5.261906e+09  \n75%    6.766325e+09  \nmax    9.980711e+09  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>row_id</th>\n      <th>x</th>\n      <th>y</th>\n      <th>accuracy</th>\n      <th>time</th>\n      <th>place_id</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>count</th>\n      <td>1.771000e+04</td>\n      <td>17710.000000</td>\n      <td>17710.000000</td>\n      <td>17710.000000</td>\n      <td>17710.000000</td>\n      <td>1.771000e+04</td>\n    </tr>\n    <tr>\n      <th>mean</th>\n      <td>1.450569e+07</td>\n      <td>1.122538</td>\n      <td>2.632309</td>\n      <td>82.482101</td>\n      <td>397551.263128</td>\n      <td>5.129895e+09</td>\n    </tr>\n    <tr>\n      <th>std</th>\n      <td>8.353805e+06</td>\n      <td>0.077086</td>\n      <td>0.070144</td>\n      <td>113.613227</td>\n      <td>234601.097883</td>\n      <td>2.357399e+09</td>\n    </tr>\n    <tr>\n      <th>min</th>\n      <td>6.000000e+02</td>\n      <td>1.000100</td>\n      <td>2.500100</td>\n      <td>1.000000</td>\n      <td>119.000000</td>\n      <td>1.012024e+09</td>\n    </tr>\n    <tr>\n      <th>25%</th>\n      <td>7.327816e+06</td>\n      <td>1.049200</td>\n      <td>2.573800</td>\n      <td>25.000000</td>\n      <td>174069.750000</td>\n      <td>3.312464e+09</td>\n    </tr>\n    <tr>\n      <th>50%</th>\n      <td>1.443071e+07</td>\n      <td>1.123300</td>\n      <td>2.642300</td>\n      <td>62.000000</td>\n      <td>403387.500000</td>\n      <td>5.261906e+09</td>\n    </tr>\n    <tr>\n      <th>75%</th>\n      <td>2.163463e+07</td>\n      <td>1.190500</td>\n      <td>2.687800</td>\n      <td>75.000000</td>\n      <td>602111.750000</td>\n      <td>6.766325e+09</td>\n    </tr>\n    <tr>\n      <th>max</th>\n      <td>2.911215e+07</td>\n      <td>1.249900</td>\n      <td>2.749900</td>\n      <td>1004.000000</td>\n      <td>786218.000000</td>\n      <td>9.980711e+09</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.describe()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-11T06:46:02.147866400Z",
     "start_time": "2024-07-11T06:46:02.101588700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "600    1970-01-01 18:09:40\n",
      "957    1970-01-10 02:11:10\n",
      "4345   1970-01-05 15:08:02\n",
      "4735   1970-01-06 23:03:03\n",
      "5580   1970-01-09 11:26:50\n",
      "6090   1970-01-02 16:25:07\n",
      "6234   1970-01-04 15:52:57\n",
      "6350   1970-01-01 10:13:36\n",
      "7468   1970-01-09 15:26:06\n",
      "8478   1970-01-08 23:52:02\n",
      "Name: time, dtype: datetime64[ns]\n"
     ]
    }
   ],
   "source": [
    "# 处理时间的数据\n",
    "time_value = pd.to_datetime(data['time'], unit='s')\n",
    "\n",
    "print(time_value.head(10))  #最大时间是1月10号"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-11T06:49:10.621871300Z",
     "start_time": "2024-07-11T06:49:10.609859200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------------------------------------\n",
      "DatetimeIndex(['1970-01-01 18:09:40', '1970-01-10 02:11:10',\n",
      "               '1970-01-05 15:08:02', '1970-01-06 23:03:03',\n",
      "               '1970-01-09 11:26:50', '1970-01-02 16:25:07',\n",
      "               '1970-01-04 15:52:57', '1970-01-01 10:13:36',\n",
      "               '1970-01-09 15:26:06', '1970-01-08 23:52:02'],\n",
      "              dtype='datetime64[ns]', name='time', freq=None)\n"
     ]
    }
   ],
   "source": [
    "# 把日期格式转换成 字典格式，把年，月，日，时，分，秒转换为字典格式，\n",
    "time_value = pd.DatetimeIndex(time_value)\n",
    "#\n",
    "print('-' * 50)\n",
    "print(time_value[0:10])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T06:49:43.513375300Z",
     "start_time": "2024-07-11T06:49:43.470947100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "data": {
      "text/plain": "(17710, 6)"
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-17T02:41:30.352561600Z",
     "start_time": "2024-04-17T02:41:30.334573100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------------------------------------\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "--------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": "      row_id       x       y  accuracy    place_id  day  hour  weekday\n600      600  1.2214  2.7023        17  6683426742    1    18        3\n957      957  1.1832  2.6891        58  6683426742   10     2        5\n4345    4345  1.1935  2.6550        11  6889790653    5    15        0\n4735    4735  1.1452  2.6074        49  6822359752    6    23        1\n5580    5580  1.0089  2.7287        19  1527921905    9    11        4",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>row_id</th>\n      <th>x</th>\n      <th>y</th>\n      <th>accuracy</th>\n      <th>place_id</th>\n      <th>day</th>\n      <th>hour</th>\n      <th>weekday</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>600</th>\n      <td>600</td>\n      <td>1.2214</td>\n      <td>2.7023</td>\n      <td>17</td>\n      <td>6683426742</td>\n      <td>1</td>\n      <td>18</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>957</th>\n      <td>957</td>\n      <td>1.1832</td>\n      <td>2.6891</td>\n      <td>58</td>\n      <td>6683426742</td>\n      <td>10</td>\n      <td>2</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>4345</th>\n      <td>4345</td>\n      <td>1.1935</td>\n      <td>2.6550</td>\n      <td>11</td>\n      <td>6889790653</td>\n      <td>5</td>\n      <td>15</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>4735</th>\n      <td>4735</td>\n      <td>1.1452</td>\n      <td>2.6074</td>\n      <td>49</td>\n      <td>6822359752</td>\n      <td>6</td>\n      <td>23</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>5580</th>\n      <td>5580</td>\n      <td>1.0089</td>\n      <td>2.7287</td>\n      <td>19</td>\n      <td>1527921905</td>\n      <td>9</td>\n      <td>11</td>\n      <td>4</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print('-' * 50)\n",
    "# 构造一些特征，执行的警告是因为我们的操作是复制，loc是直接放入\n",
    "print(type(data))\n",
    "# data['day'] = time_value.day\n",
    "# data['hour'] = time_value.hour\n",
    "# data['weekday'] = time_value.weekday\n",
    "#日期，是否是周末，小时对于个人行为的影响是较大的(例如吃饭时间去饭店，看电影时间去电影院等),所以才做下面的处理\n",
    "data.insert(data.shape[1], 'day', time_value.day) #data.shape[1]是代表插入到最后的意思,一个月的哪一天\n",
    "data.insert(data.shape[1], 'hour', time_value.hour)#是否去一个地方打卡，早上，中午，晚上是有影响的\n",
    "data.insert(data.shape[1], 'weekday', time_value.weekday) #0代表周一，6代表周日，星期几\n",
    "\n",
    "#\n",
    "# 把时间戳特征删除\n",
    "data = data.drop(['time'], axis=1)\n",
    "print('-' * 50)\n",
    "data.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T06:51:57.629025Z",
     "start_time": "2024-07-11T06:51:57.584518400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "data": {
      "text/plain": "3"
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#星期天，实际weekday的值是6\n",
    "per = pd.Period('1970-01-01 18:00', 'h')\n",
    "per.weekday"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-17T02:41:30.550450600Z",
     "start_time": "2024-04-17T02:41:30.382544900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "data": {
      "text/plain": "             row_id             x             y      accuracy      place_id  \\\ncount  1.771000e+04  17710.000000  17710.000000  17710.000000  1.771000e+04   \nmean   1.450569e+07      1.122538      2.632309     82.482101  5.129895e+09   \nstd    8.353805e+06      0.077086      0.070144    113.613227  2.357399e+09   \nmin    6.000000e+02      1.000100      2.500100      1.000000  1.012024e+09   \n25%    7.327816e+06      1.049200      2.573800     25.000000  3.312464e+09   \n50%    1.443071e+07      1.123300      2.642300     62.000000  5.261906e+09   \n75%    2.163463e+07      1.190500      2.687800     75.000000  6.766325e+09   \nmax    2.911215e+07      1.249900      2.749900   1004.000000  9.980711e+09   \n\n                day          hour       weekday  \ncount  17710.000000  17710.000000  17710.000000  \nmean       5.101863     11.485545      3.092377  \nstd        2.709287      6.932195      1.680218  \nmin        1.000000      0.000000      0.000000  \n25%        3.000000      6.000000      2.000000  \n50%        5.000000     12.000000      3.000000  \n75%        7.000000     17.000000      4.000000  \nmax       10.000000     23.000000      6.000000  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>row_id</th>\n      <th>x</th>\n      <th>y</th>\n      <th>accuracy</th>\n      <th>place_id</th>\n      <th>day</th>\n      <th>hour</th>\n      <th>weekday</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>count</th>\n      <td>1.771000e+04</td>\n      <td>17710.000000</td>\n      <td>17710.000000</td>\n      <td>17710.000000</td>\n      <td>1.771000e+04</td>\n      <td>17710.000000</td>\n      <td>17710.000000</td>\n      <td>17710.000000</td>\n    </tr>\n    <tr>\n      <th>mean</th>\n      <td>1.450569e+07</td>\n      <td>1.122538</td>\n      <td>2.632309</td>\n      <td>82.482101</td>\n      <td>5.129895e+09</td>\n      <td>5.101863</td>\n      <td>11.485545</td>\n      <td>3.092377</td>\n    </tr>\n    <tr>\n      <th>std</th>\n      <td>8.353805e+06</td>\n      <td>0.077086</td>\n      <td>0.070144</td>\n      <td>113.613227</td>\n      <td>2.357399e+09</td>\n      <td>2.709287</td>\n      <td>6.932195</td>\n      <td>1.680218</td>\n    </tr>\n    <tr>\n      <th>min</th>\n      <td>6.000000e+02</td>\n      <td>1.000100</td>\n      <td>2.500100</td>\n      <td>1.000000</td>\n      <td>1.012024e+09</td>\n      <td>1.000000</td>\n      <td>0.000000</td>\n      <td>0.000000</td>\n    </tr>\n    <tr>\n      <th>25%</th>\n      <td>7.327816e+06</td>\n      <td>1.049200</td>\n      <td>2.573800</td>\n      <td>25.000000</td>\n      <td>3.312464e+09</td>\n      <td>3.000000</td>\n      <td>6.000000</td>\n      <td>2.000000</td>\n    </tr>\n    <tr>\n      <th>50%</th>\n      <td>1.443071e+07</td>\n      <td>1.123300</td>\n      <td>2.642300</td>\n      <td>62.000000</td>\n      <td>5.261906e+09</td>\n      <td>5.000000</td>\n      <td>12.000000</td>\n      <td>3.000000</td>\n    </tr>\n    <tr>\n      <th>75%</th>\n      <td>2.163463e+07</td>\n      <td>1.190500</td>\n      <td>2.687800</td>\n      <td>75.000000</td>\n      <td>6.766325e+09</td>\n      <td>7.000000</td>\n      <td>17.000000</td>\n      <td>4.000000</td>\n    </tr>\n    <tr>\n      <th>max</th>\n      <td>2.911215e+07</td>\n      <td>1.249900</td>\n      <td>2.749900</td>\n      <td>1004.000000</td>\n      <td>9.980711e+09</td>\n      <td>10.000000</td>\n      <td>23.000000</td>\n      <td>6.000000</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#观察数据，看下是否有空值，异常值\n",
    "data.describe()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T06:53:41.203974400Z",
     "start_time": "2024-07-11T06:53:41.160805500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "outputs": [
    {
     "data": {
      "text/plain": "            row_id     x     y  accuracy   day  hour  weekday\nplace_id                                                     \n1012023972       1     1     1         1     1     1        1\n1057182134       1     1     1         1     1     1        1\n1059958036       3     3     3         3     3     3        3\n1085266789       1     1     1         1     1     1        1\n1097200869    1044  1044  1044      1044  1044  1044     1044\n...            ...   ...   ...       ...   ...   ...      ...\n9904182060       1     1     1         1     1     1        1\n9915093501       1     1     1         1     1     1        1\n9946198589       1     1     1         1     1     1        1\n9950190890       1     1     1         1     1     1        1\n9980711012       5     5     5         5     5     5        5\n\n[805 rows x 7 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>row_id</th>\n      <th>x</th>\n      <th>y</th>\n      <th>accuracy</th>\n      <th>day</th>\n      <th>hour</th>\n      <th>weekday</th>\n    </tr>\n    <tr>\n      <th>place_id</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>1012023972</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>1057182134</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>1059958036</th>\n      <td>3</td>\n      <td>3</td>\n      <td>3</td>\n      <td>3</td>\n      <td>3</td>\n      <td>3</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>1085266789</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>1097200869</th>\n      <td>1044</td>\n      <td>1044</td>\n      <td>1044</td>\n      <td>1044</td>\n      <td>1044</td>\n      <td>1044</td>\n      <td>1044</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>9904182060</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>9915093501</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>9946198589</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>9950190890</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>9980711012</th>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n    </tr>\n  </tbody>\n</table>\n<p>805 rows × 7 columns</p>\n</div>"
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# # 把签到数量少于n个目标位置删除，place_id是标签，即目标值\n",
    "place_count = data.groupby('place_id').count()\n",
    "place_count"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T06:53:54.134139600Z",
     "start_time": "2024-07-11T06:53:54.105164100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "outputs": [
    {
     "data": {
      "text/plain": "count     805.000000\nmean       22.000000\nstd        88.955632\nmin         1.000000\n25%         1.000000\n50%         2.000000\n75%         5.000000\nmax      1044.000000\nName: x, dtype: float64"
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "place_count['x'].describe() #打卡地点总计805个，50%打卡小于2次"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T06:54:09.354513700Z",
     "start_time": "2024-07-11T06:54:09.328504600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "outputs": [
    {
     "data": {
      "text/plain": "       place_id  row_id     x     y  accuracy   day  hour  weekday\n0    1097200869    1044  1044  1044      1044  1044  1044     1044\n1    1228935308     120   120   120       120   120   120      120\n2    1267801529      58    58    58        58    58    58       58\n3    1278040507      15    15    15        15    15    15       15\n4    1285051622      21    21    21        21    21    21       21\n..          ...     ...   ...   ...       ...   ...   ...      ...\n234  9741307878       5     5     5         5     5     5        5\n235  9753855529      21    21    21        21    21    21       21\n236  9806043737       6     6     6         6     6     6        6\n237  9809476069      23    23    23        23    23    23       23\n238  9980711012       5     5     5         5     5     5        5\n\n[239 rows x 8 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>place_id</th>\n      <th>row_id</th>\n      <th>x</th>\n      <th>y</th>\n      <th>accuracy</th>\n      <th>day</th>\n      <th>hour</th>\n      <th>weekday</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1097200869</td>\n      <td>1044</td>\n      <td>1044</td>\n      <td>1044</td>\n      <td>1044</td>\n      <td>1044</td>\n      <td>1044</td>\n      <td>1044</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1228935308</td>\n      <td>120</td>\n      <td>120</td>\n      <td>120</td>\n      <td>120</td>\n      <td>120</td>\n      <td>120</td>\n      <td>120</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1267801529</td>\n      <td>58</td>\n      <td>58</td>\n      <td>58</td>\n      <td>58</td>\n      <td>58</td>\n      <td>58</td>\n      <td>58</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1278040507</td>\n      <td>15</td>\n      <td>15</td>\n      <td>15</td>\n      <td>15</td>\n      <td>15</td>\n      <td>15</td>\n      <td>15</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1285051622</td>\n      <td>21</td>\n      <td>21</td>\n      <td>21</td>\n      <td>21</td>\n      <td>21</td>\n      <td>21</td>\n      <td>21</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>234</th>\n      <td>9741307878</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>235</th>\n      <td>9753855529</td>\n      <td>21</td>\n      <td>21</td>\n      <td>21</td>\n      <td>21</td>\n      <td>21</td>\n      <td>21</td>\n      <td>21</td>\n    </tr>\n    <tr>\n      <th>236</th>\n      <td>9806043737</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n    </tr>\n    <tr>\n      <th>237</th>\n      <td>9809476069</td>\n      <td>23</td>\n      <td>23</td>\n      <td>23</td>\n      <td>23</td>\n      <td>23</td>\n      <td>23</td>\n      <td>23</td>\n    </tr>\n    <tr>\n      <th>238</th>\n      <td>9980711012</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n      <td>5</td>\n    </tr>\n  </tbody>\n</table>\n<p>239 rows × 8 columns</p>\n</div>"
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# # 把index变为0,1,2，3,4,5,6这种效果，从零开始排，原来的index是row_id\n",
    "#只选择去的人大于3的数据，认为1,2,3的是噪音，这个地方去的人很少，不用推荐给其他人\n",
    "tf = place_count[place_count.row_id > 3].reset_index()\n",
    "tf  #剩余的签到地点"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T06:56:39.908743600Z",
     "start_time": "2024-07-11T06:56:39.877483300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "outputs": [
    {
     "data": {
      "text/plain": "(16918, 8)"
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 根据设定的地点目标值，对原本的样本进行过滤\n",
    "#isin可以过滤某一列要在一组值\n",
    "data = data[data['place_id'].isin(tf.place_id)]\n",
    "data.shape"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T06:57:23.227967200Z",
     "start_time": "2024-07-11T06:57:23.214625600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(16918, 6)\n",
      "Index(['x', 'y', 'accuracy', 'day', 'hour', 'weekday'], dtype='object')\n"
     ]
    }
   ],
   "source": [
    "# # 取出数据当中的特征值和目标值\n",
    "y = data['place_id']\n",
    "# 删除目标值，保留特征值，\n",
    "x = data.drop(['place_id'], axis=1)\n",
    "# 删除无用的特征值，row_id是索引,这就是噪音\n",
    "x = x.drop(['row_id'], axis=1)\n",
    "print(x.shape)\n",
    "print(x.columns)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T07:01:23.875449200Z",
     "start_time": "2024-07-11T07:01:23.868900700Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 上面预处理完成"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "outputs": [],
   "source": [
    "# li = load_iris()\n",
    "# x,y=li.data,li.target"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-04-17T02:41:30.779320300Z",
     "start_time": "2024-04-17T02:41:30.664384300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 1.12295735  2.63237278 81.34938525  5.10064628 11.44293821  3.10135561]\n",
      "[5.98489138e-03 4.86857391e-03 1.19597480e+04 7.32837915e+00\n",
      " 4.83742660e+01 2.81838404e+00]\n",
      "--------------------------------------------------\n",
      "[ 1.12295735  2.63237278 81.34938525  5.10064628 11.44293821  3.10135561]\n",
      "[5.98489138e-03 4.86857391e-03 1.19597480e+04 7.32837915e+00\n",
      " 4.83742660e+01 2.81838404e+00]\n"
     ]
    }
   ],
   "source": [
    "# 进行数据的分割训练集合测试集\n",
    "x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=1)\n",
    "\n",
    "# 特征工程（标准化）,下面3行注释，一开始我们不进行标准化，看下效果，目标值要不要标准化？\n",
    "std = StandardScaler()\n",
    "# #\n",
    "# # # 对测试集和训练集的特征值进行标准化,服务于knn fit\n",
    "x_train = std.fit_transform(x_train)\n",
    "# # transform返回的是copy，不在原有的输入对象中去修改\n",
    "# print(id(x_test))\n",
    "print(std.mean_)\n",
    "print(std.var_)\n",
    "x_test = std.transform(x_test)  #transfrom不再进行均值和方差的计算，是在原有的基础上去标准化\n",
    "print('-' * 50)\n",
    "# print(id(x_test))\n",
    "print(std.mean_)\n",
    "print(std.var_)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T07:02:55.197451200Z",
     "start_time": "2024-07-11T07:02:55.144212200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "outputs": [
    {
     "data": {
      "text/plain": "(12688, 6)"
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_train.shape"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-11T07:04:57.631719200Z",
     "start_time": "2024-07-11T07:04:57.606272500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "预测的目标签到位置为： [5689129232 1097200869 2355236719 9632980559 6424972551 4022692381\n",
      " 8048985799 6683426742 1435128522 3312463746]\n",
      "预测的准确率: 0.484160756501182\n"
     ]
    }
   ],
   "source": [
    "# # 进行算法流程 # 超参数，可以通过设置n_neighbors=5，来调整结果好坏\n",
    "knn = KNeighborsClassifier(n_neighbors=6)\n",
    "\n",
    "# # fit， predict,score，训练，knn的fit是不训练的，只是把训练集的特征值和目标值放入到内存中\n",
    "knn.fit(x_train, y_train)\n",
    "# # #\n",
    "# # # 得出预测结果\n",
    "y_predict = knn.predict(x_test)\n",
    "# #\n",
    "print(\"预测的目标签到位置为：\", y_predict[0:10])\n",
    "# # #\n",
    "# # # # 得出准确率,是评估指标\n",
    "print(\"预测的准确率:\", knn.score(x_test, y_test))\n",
    "# print(y_predict)\n",
    "# y_test"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T07:09:16.397919200Z",
     "start_time": "2024-07-11T07:09:15.675247300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1970-01-10 02:23:38\n"
     ]
    }
   ],
   "source": [
    "print(max(time_value))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 调超参的方法，网格搜索"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Administrator\\AppData\\Roaming\\Python\\Python312\\site-packages\\sklearn\\model_selection\\_split.py:776: UserWarning: The least populated class in y has only 1 members, which is less than n_splits=3.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在测试集上准确率： 0.49763593380614657\n",
      "在交叉验证当中最好的结果： 0.4816362349278435\n",
      "选择最好的模型是： KNeighborsClassifier(n_neighbors=12, weights='distance')\n",
      "每个超参数每次交叉验证的结果：\n"
     ]
    },
    {
     "data": {
      "text/plain": "{'mean_fit_time': array([0.02048691, 0.01916122, 0.01731531, 0.01982721, 0.01766006,\n        0.01865705, 0.01728249, 0.02582089, 0.01798177, 0.01582281]),\n 'std_fit_time': array([0.00107879, 0.00271418, 0.00047079, 0.00383914, 0.00235725,\n        0.00262503, 0.00191062, 0.0008485 , 0.00141512, 0.0011672 ]),\n 'mean_score_time': array([0.26846647, 0.09583902, 0.27917449, 0.11019945, 0.31781475,\n        0.14814862, 0.33950456, 0.32303731, 0.32426349, 0.17713237]),\n 'std_score_time': array([0.00959243, 0.00926416, 0.00615404, 0.00519303, 0.01333767,\n        0.00110336, 0.02202146, 0.01904355, 0.00673751, 0.00521987]),\n 'param_n_neighbors': masked_array(data=[3, 3, 5, 5, 10, 10, 12, 12, 15, 15],\n              mask=[False, False, False, False, False, False, False, False,\n                    False, False],\n        fill_value=999999),\n 'param_weights': masked_array(data=['uniform', 'distance', 'uniform', 'distance',\n                    'uniform', 'distance', 'uniform', 'distance',\n                    'uniform', 'distance'],\n              mask=[False, False, False, False, False, False, False, False,\n                    False, False],\n        fill_value='?',\n             dtype=object),\n 'params': [{'n_neighbors': 3, 'weights': 'uniform'},\n  {'n_neighbors': 3, 'weights': 'distance'},\n  {'n_neighbors': 5, 'weights': 'uniform'},\n  {'n_neighbors': 5, 'weights': 'distance'},\n  {'n_neighbors': 10, 'weights': 'uniform'},\n  {'n_neighbors': 10, 'weights': 'distance'},\n  {'n_neighbors': 12, 'weights': 'uniform'},\n  {'n_neighbors': 12, 'weights': 'distance'},\n  {'n_neighbors': 15, 'weights': 'uniform'},\n  {'n_neighbors': 15, 'weights': 'distance'}],\n 'split0_test_score': array([0.44468085, 0.4534279 , 0.4607565 , 0.47399527, 0.46170213,\n        0.48014184, 0.45650118, 0.48108747, 0.45508274, 0.47895981]),\n 'split1_test_score': array([0.43390873, 0.4542445 , 0.45660913, 0.47528967, 0.45542681,\n        0.48238354, 0.45329865, 0.48049184, 0.44809648, 0.47623552]),\n 'split2_test_score': array([0.43982029, 0.4561362 , 0.45684559, 0.47221565, 0.4618113 ,\n        0.48191062, 0.45897375, 0.48332939, 0.46062899, 0.48049184]),\n 'mean_test_score': array([0.43946996, 0.45460287, 0.45807041, 0.47383353, 0.45964675,\n        0.48147867, 0.45625786, 0.48163623, 0.45460274, 0.47856239]),\n 'std_test_score': array([0.00440467, 0.00113433, 0.00190181, 0.00126016, 0.00298428,\n        0.00096479, 0.00232323, 0.00122169, 0.00512762, 0.00176021]),\n 'rank_test_score': array([10,  8,  6,  4,  5,  2,  7,  1,  9,  3])}"
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#网格搜索时讲解\n",
    "# # 构造一些参数（超参）的值进行搜索\n",
    "param = {\"n_neighbors\": [3, 5, 10, 12, 15],'weights':['uniform', 'distance']}\n",
    "#\n",
    "# 进行网格搜索，cv=3是3折交叉验证，用其中2折训练，1折验证\n",
    "gc = GridSearchCV(knn, param_grid=param, cv=3)\n",
    "\n",
    "gc.fit(x_train, y_train)  #你给它的x_train，它又分为训练集，验证集\n",
    "\n",
    "# 预测准确率，为了给大家看看\n",
    "print(\"在测试集上准确率：\", gc.score(x_test, y_test))\n",
    "\n",
    "print(\"在交叉验证当中最好的结果：\", gc.best_score_) #最好的结果\n",
    "\n",
    "print(\"选择最好的模型是：\", gc.best_estimator_) #最好的模型,告诉你用了哪些参数\n",
    "\n",
    "print(\"每个超参数每次交叉验证的结果：\")\n",
    "gc.cv_results_"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T07:58:54.973610200Z",
     "start_time": "2024-07-11T07:58:47.005138100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18846\n",
      "--------------------------------------------------\n",
      "From: Mamatha Devineni Ratnam <mr47+@andrew.cmu.edu>\n",
      "Subject: Pens fans reactions\n",
      "Organization: Post Office, Carnegie Mellon, Pittsburgh, PA\n",
      "Lines: 12\n",
      "NNTP-Posting-Host: po4.andrew.cmu.edu\n",
      "\n",
      "\n",
      "\n",
      "I am sure some bashers of Pens fans are pretty confused about the lack\n",
      "of any kind of posts about the recent Pens massacre of the Devils. Actually,\n",
      "I am  bit puzzled too and a bit relieved. However, I am going to put an end\n",
      "to non-PIttsburghers' relief with a bit of praise for the Pens. Man, they\n",
      "are killing those Devils worse than I thought. Jagr just showed you why\n",
      "he is much better than his regular season stats. He is also a lot\n",
      "fo fun to watch in the playoffs. Bowman should let JAgr have a lot of\n",
      "fun in the next couple of games since the Pens are going to beat the pulp out of Jersey anyway. I was very disappointed not to see the Islanders lose the final\n",
      "regular season game.          PENS RULE!!!\n",
      "\n",
      "\n",
      "--------------------------------------------------\n",
      "[10  3 17 ...  3  1  7]\n",
      "[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19]\n",
      "['alt.atheism', 'comp.graphics', 'comp.os.ms-windows.misc', 'comp.sys.ibm.pc.hardware', 'comp.sys.mac.hardware', 'comp.windows.x', 'misc.forsale', 'rec.autos', 'rec.motorcycles', 'rec.sport.baseball', 'rec.sport.hockey', 'sci.crypt', 'sci.electronics', 'sci.med', 'sci.space', 'soc.religion.christian', 'talk.politics.guns', 'talk.politics.mideast', 'talk.politics.misc', 'talk.religion.misc']\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "朴素贝叶斯进行文本分类\n",
    ":return: None\n",
    "\"\"\"\n",
    "news = fetch_20newsgroups(subset='all', data_home='data')\n",
    "\n",
    "print(len(news.data))  #样本数，包含的特征\n",
    "print('-'*50)\n",
    "print(news.data[0]) #第一个样本 特征\n",
    "print('-'*50)\n",
    "print(news.target) #标签\n",
    "print(np.unique(news.target)) #标签的类别\n",
    "print(news.target_names) #标签的名字"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T08:27:59.214399200Z",
     "start_time": "2024-07-11T08:27:58.768437100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------------------------------------\n",
      "153196\n"
     ]
    }
   ],
   "source": [
    "print('-'*50)\n",
    "# 进行数据分割\n",
    "x_train, x_test, y_train, y_test = train_test_split(news.data, news.target, test_size=0.25, random_state=1)\n",
    "\n",
    "# 对数据集进行特征抽取\n",
    "tf = TfidfVectorizer()\n",
    "\n",
    "# 以训练集当中的词的列表进行每篇文章重要性统计['a','b','c','d']\n",
    "x_train = tf.fit_transform(x_train)\n",
    "#针对特征内容，可以自行打印，下面的打印可以得到特征数目，总计有15万特征\n",
    "print(len(tf.get_feature_names_out()))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T08:30:10.707851700Z",
     "start_time": "2024-07-11T08:30:04.877903Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "murky\n"
     ]
    }
   ],
   "source": [
    "print(tf.get_feature_names_out()[100000])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T08:30:23.422937800Z",
     "start_time": "2024-07-11T08:30:23.166429600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['00' '000' '0000' '00000' '0000000004' '0000000005' '0000000667'\n",
      " '0000001200' '000003' '000005102000']\n"
     ]
    }
   ],
   "source": [
    "print(tf.get_feature_names_out()[0:10])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T08:30:25.904205100Z",
     "start_time": "2024-07-11T08:30:25.669335900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "outputs": [
    {
     "data": {
      "text/plain": "0.23983407020568848"
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "# 进行朴素贝叶斯算法的预测,alpha是拉普拉斯平滑系数，分子和分母加上一个系数，分母加alpha*特征词数目\n",
    "mlt = MultinomialNB(alpha=1.0)\n",
    "\n",
    "# print(x_train.toarray())\n",
    "# 训练\n",
    "start=time.time()\n",
    "mlt.fit(x_train, y_train)\n",
    "end=time.time()\n",
    "end-start #统计训练时间"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T08:34:07.080494Z",
     "start_time": "2024-07-11T08:34:06.835118800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "153196\n"
     ]
    }
   ],
   "source": [
    "x_transform_test = tf.transform(x_test)  #特征数目不发生改变\n",
    "print(len(tf.get_feature_names_out())) #查看特征数目"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-11T08:36:25.965737700Z",
     "start_time": "2024-07-11T08:36:23.731589500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "预测的前面10篇文章类别为： [16 19 18  1  9 15  1  2 16 13]\n",
      "准确率为： 0.8518675721561969\n"
     ]
    },
    {
     "data": {
      "text/plain": "0.10379219055175781"
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "start=time.time()\n",
    "y_predict = mlt.predict(x_transform_test)\n",
    "\n",
    "print(\"预测的前面10篇文章类别为：\", y_predict[0:10])\n",
    "\n",
    "# 得出准确率,这个是很难提高准确率，为什么呢？\n",
    "print(\"准确率为：\", mlt.score(x_transform_test, y_test))\n",
    "end=time.time()\n",
    "end-start"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T08:37:10.572020800Z",
     "start_time": "2024-07-11T08:37:10.465998900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "4712"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#预测的文章数目\n",
    "len(y_predict)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-17T03:40:11.018365400Z",
     "start_time": "2024-04-17T03:40:10.999378200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                          precision    recall  f1-score   support\n",
      "\n",
      "             alt.atheism       0.91      0.77      0.83       199\n",
      "           comp.graphics       0.83      0.79      0.81       242\n",
      " comp.os.ms-windows.misc       0.89      0.83      0.86       263\n",
      "comp.sys.ibm.pc.hardware       0.80      0.83      0.81       262\n",
      "   comp.sys.mac.hardware       0.90      0.88      0.89       234\n",
      "          comp.windows.x       0.92      0.85      0.88       230\n",
      "            misc.forsale       0.96      0.67      0.79       257\n",
      "               rec.autos       0.90      0.87      0.88       265\n",
      "         rec.motorcycles       0.90      0.95      0.92       251\n",
      "      rec.sport.baseball       0.89      0.96      0.93       226\n",
      "        rec.sport.hockey       0.95      0.98      0.96       262\n",
      "               sci.crypt       0.76      0.97      0.85       257\n",
      "         sci.electronics       0.84      0.80      0.82       229\n",
      "                 sci.med       0.97      0.86      0.91       249\n",
      "               sci.space       0.92      0.96      0.94       256\n",
      "  soc.religion.christian       0.55      0.98      0.70       243\n",
      "      talk.politics.guns       0.76      0.96      0.85       234\n",
      "   talk.politics.mideast       0.93      0.99      0.96       224\n",
      "      talk.politics.misc       0.98      0.56      0.72       197\n",
      "      talk.religion.misc       0.97      0.26      0.41       132\n",
      "\n",
      "                accuracy                           0.85      4712\n",
      "               macro avg       0.88      0.84      0.84      4712\n",
      "            weighted avg       0.87      0.85      0.85      4712\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 目前这个场景我们不需要召回率，support是真实的为那个类别的有多少个样本\n",
    "print(classification_report(y_test, y_predict,\n",
    "      target_names=news.target_names))\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T08:49:08.460150Z",
     "start_time": "2024-07-11T08:49:08.414964900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "outputs": [
    {
     "data": {
      "text/plain": "(4712,)"
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_test.shape #测试集中有多少 样本"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-11T08:41:49.409254600Z",
     "start_time": "2024-07-11T08:41:49.394684800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "199\n"
     ]
    }
   ],
   "source": [
    "y_test1 = np.where(y_test == 0, 1, 0)\n",
    "print(y_test1.sum()) #label为0的样本数"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-11T08:43:10.478704300Z",
     "start_time": "2024-07-11T08:43:10.453125Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "168\n"
     ]
    }
   ],
   "source": [
    "y_predict1 = np.where(y_predict == 0, 1, 0)\n",
    "print(y_predict1.sum())"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-11T08:43:39.257230300Z",
     "start_time": "2024-07-11T08:43:39.242669800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "outputs": [
    {
     "data": {
      "text/plain": "153"
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(y_test1*y_predict1).sum()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-11T08:47:12.871621900Z",
     "start_time": "2024-07-11T08:47:12.859630700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "outputs": [
    {
     "data": {
      "text/plain": "0.9107142857142857"
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "153/168"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-11T08:47:47.240582700Z",
     "start_time": "2024-07-11T08:47:47.224194200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "outputs": [
    {
     "data": {
      "text/plain": "0.7688442211055276"
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "153/199"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-11T08:47:58.745023500Z",
     "start_time": "2024-07-11T08:47:58.679632Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "data": {
      "text/plain": "(19, 0)"
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "max(y_test),min(y_test)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-04-18T01:45:20.411727800Z",
     "start_time": "2024-04-18T01:45:20.386731300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "230\n",
      "214\n",
      "AUC指标： 0.924078924393225\n"
     ]
    }
   ],
   "source": [
    "# 把0-19总计20个分类，变为0和1\n",
    "# 5是可以改为0到19的\n",
    "y_test1 = np.where(y_test == 5, 1, 0)\n",
    "print(y_test1.sum()) #label为5的样本数\n",
    "y_predict1 = np.where(y_predict == 5, 1, 0)\n",
    "print(y_predict1.sum())\n",
    "# roc_auc_score的y_test只能是二分类,针对多分类如何计算AUC\n",
    "print(\"AUC指标：\", roc_auc_score(y_test1, y_predict1))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-11T08:50:53.791629600Z",
     "start_time": "2024-07-11T08:50:53.767458500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "data": {
      "text/plain": "(array([0, 0, 0, ..., 0, 0, 0]), array([0, 0, 0, ..., 0, 0, 0]))"
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_test1,y_predict1"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-04-18T01:49:37.220158600Z",
     "start_time": "2024-04-18T01:49:37.200170Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "196\n",
      "34\n",
      "4464\n"
     ]
    }
   ],
   "source": [
    "#算多分类的精确率，召回率，F1-score\n",
    "FP=np.where((np.array(y_test1)-np.array(y_predict1))==-1,1,0).sum()   #FP是18\n",
    "TP=y_predict1.sum()-FP #TP是196\n",
    "print(TP)\n",
    "FN=np.where((np.array(y_test1)-np.array(y_predict1))==1,1,0).sum() #FN是34\n",
    "print(FN)#FN是1\n",
    "TN=np.where(y_test1==0,1,0).sum()-FP  #4464\n",
    "print(TN)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-18T02:02:14.916876200Z",
     "start_time": "2024-04-18T02:02:14.879886600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [
    {
     "data": {
      "text/plain": "0.9158878504672897"
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "TP/(TP+FP) #精确率"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-04-18T02:02:17.581304500Z",
     "start_time": "2024-04-18T02:02:17.543326400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "data": {
      "text/plain": "0.8521739130434782"
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "TP/(TP+FN)  #召回率"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-04-18T02:03:10.184400300Z",
     "start_time": "2024-04-18T02:03:10.130432500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "outputs": [
    {
     "data": {
      "text/plain": "0.8828828828828829"
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#F1-score\n",
    "2*TP/(2*TP+FP+FN)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-04-18T02:03:31.272589Z",
     "start_time": "2024-04-18T02:03:31.224618200Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "del news\n",
    "del x_train\n",
    "del x_test\n",
    "del y_test\n",
    "del y_predict\n",
    "del tf"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 3 决策树"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split, GridSearchCV\n",
    "from sklearn.feature_extraction import DictVectorizer\n",
    "from sklearn.tree import DecisionTreeClassifier, export_graphviz\n",
    "from sklearn.ensemble import RandomForestClassifier\n",
    "import pandas as pd\n",
    "import numpy as np"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:41.534060500Z",
     "start_time": "2024-07-12T06:58:36.089693300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "data": {
      "text/plain": "-5.0"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.log2(1/32)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:41.622569900Z",
     "start_time": "2024-07-12T06:58:41.540055200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "data": {
      "text/plain": "-1.0"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 / 2 * np.log2(1 /2) + 1 / 2 * np.log2(1 /2)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:41.629567Z",
     "start_time": "2024-07-12T06:58:41.565013700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "-0.9182958340544896"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 / 3 * np.log2(1 / 3) + 2 / 3 * np.log2(2 / 3)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:41.630566500Z",
     "start_time": "2024-07-12T06:58:41.595585200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "data": {
      "text/plain": "-0.08079313589591118"
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0.01 * np.log2(0.01) + 0.99 * np.log2(0.99)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:41.631567700Z",
     "start_time": "2024-07-12T06:58:41.596585300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1313 entries, 0 to 1312\n",
      "Data columns (total 11 columns):\n",
      " #   Column     Non-Null Count  Dtype  \n",
      "---  ------     --------------  -----  \n",
      " 0   row.names  1313 non-null   int64  \n",
      " 1   pclass     1313 non-null   object \n",
      " 2   survived   1313 non-null   int64  \n",
      " 3   name       1313 non-null   object \n",
      " 4   age        633 non-null    float64\n",
      " 5   embarked   821 non-null    object \n",
      " 6   home.dest  754 non-null    object \n",
      " 7   room       77 non-null     object \n",
      " 8   ticket     69 non-null     object \n",
      " 9   boat       347 non-null    object \n",
      " 10  sex        1313 non-null   object \n",
      "dtypes: float64(1), int64(2), object(8)\n",
      "memory usage: 113.0+ KB\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "决策树对泰坦尼克号进行预测生死\n",
    ":return: None\n",
    "\"\"\"\n",
    "# 获取数据\n",
    "titan = pd.read_csv(\"./data/titanic.txt\")\n",
    "titan.info()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:41.809781100Z",
     "start_time": "2024-07-12T06:58:41.623569400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1313 entries, 0 to 1312\n",
      "Data columns (total 3 columns):\n",
      " #   Column  Non-Null Count  Dtype  \n",
      "---  ------  --------------  -----  \n",
      " 0   pclass  1313 non-null   object \n",
      " 1   age     633 non-null    float64\n",
      " 2   sex     1313 non-null   object \n",
      "dtypes: float64(1), object(2)\n",
      "memory usage: 30.9+ KB\n",
      "None\n"
     ]
    },
    {
     "data": {
      "text/plain": "       pclass         age   sex\ncount    1313  633.000000  1313\nunique      3         NaN     2\ntop       3rd         NaN  male\nfreq      711         NaN   850\nmean      NaN   31.194181   NaN\nstd       NaN   14.747525   NaN\nmin       NaN    0.166700   NaN\n25%       NaN   21.000000   NaN\n50%       NaN   30.000000   NaN\n75%       NaN   41.000000   NaN\nmax       NaN   71.000000   NaN",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>pclass</th>\n      <th>age</th>\n      <th>sex</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>count</th>\n      <td>1313</td>\n      <td>633.000000</td>\n      <td>1313</td>\n    </tr>\n    <tr>\n      <th>unique</th>\n      <td>3</td>\n      <td>NaN</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>top</th>\n      <td>3rd</td>\n      <td>NaN</td>\n      <td>male</td>\n    </tr>\n    <tr>\n      <th>freq</th>\n      <td>711</td>\n      <td>NaN</td>\n      <td>850</td>\n    </tr>\n    <tr>\n      <th>mean</th>\n      <td>NaN</td>\n      <td>31.194181</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>std</th>\n      <td>NaN</td>\n      <td>14.747525</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>min</th>\n      <td>NaN</td>\n      <td>0.166700</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>25%</th>\n      <td>NaN</td>\n      <td>21.000000</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>50%</th>\n      <td>NaN</td>\n      <td>30.000000</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>75%</th>\n      <td>NaN</td>\n      <td>41.000000</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>max</th>\n      <td>NaN</td>\n      <td>71.000000</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 处理数据，找出特征值和目标值\n",
    "x = titan[['pclass', 'age', 'sex']]\n",
    "\n",
    "y = titan['survived']\n",
    "print(x.info())  # 用来判断是否有空值\n",
    "x.describe(include='all')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:41.869702100Z",
     "start_time": "2024-07-12T06:58:41.677682800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "data": {
      "text/plain": "71.0"
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.loc[:,'age'].max()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:41.871704900Z",
     "start_time": "2024-07-12T06:58:41.724653700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [],
   "source": [
    "# 一定要进行缺失值处理,填为均值\n",
    "mean=x['age'].mean()\n",
    "x.loc[:,'age']=x.loc[:,'age'].fillna(mean)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:41.873701200Z",
     "start_time": "2024-07-12T06:58:41.731258600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1313 entries, 0 to 1312\n",
      "Data columns (total 3 columns):\n",
      " #   Column  Non-Null Count  Dtype  \n",
      "---  ------  --------------  -----  \n",
      " 0   pclass  1313 non-null   object \n",
      " 1   age     1313 non-null   float64\n",
      " 2   sex     1313 non-null   object \n",
      "dtypes: float64(1), object(2)\n",
      "memory usage: 30.9+ KB\n"
     ]
    }
   ],
   "source": [
    "x.info()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:41.874698800Z",
     "start_time": "2024-07-12T06:58:41.749897500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    pclass        age     sex\n",
      "598    2nd  30.000000    male\n",
      "246    1st  62.000000    male\n",
      "905    3rd  31.194181  female\n",
      "300    1st  31.194181  female\n",
      "509    2nd  64.000000    male\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "# 分割数据集到训练集合测试集\n",
    "x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=4)\n",
    "print(x_train.head())"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:41.876697700Z",
     "start_time": "2024-07-12T06:58:41.763401Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "pandas.core.frame.DataFrame"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(x_train)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:41.877699700Z",
     "start_time": "2024-07-12T06:58:41.781280300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "data": {
      "text/plain": "334"
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum(y_train)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:42.085907900Z",
     "start_time": "2024-07-12T06:58:41.806784200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "data": {
      "text/plain": "pclass    341\nage       341\nsex       341\ndtype: int64"
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#性别是女性的数量\n",
    "x_train[x_train['sex'] == 'female'].count()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:42.114201700Z",
     "start_time": "2024-07-12T06:58:41.833769100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "outputs": [
    {
     "data": {
      "text/plain": "598     0\n246     0\n905     0\n300     0\n509     0\n       ..\n360     0\n709     0\n439     0\n174     0\n1146    0\nName: survived, Length: 984, dtype: int64"
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:42.117199900Z",
     "start_time": "2024-07-12T06:58:41.859707100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "outputs": [
    {
     "data": {
      "text/plain": "survived\n1    230\n0    111\nName: count, dtype: int64"
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#女性中存活的情况对比\n",
    "z=x_train.copy() #z是为了把特征和目标存储到一起\n",
    "z['survived'] = y_train #把目标值存储到z中\n",
    "z[z['sex'] == 'female']['survived'].value_counts() #男性中存活的情况"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:42.147488Z",
     "start_time": "2024-07-12T06:58:41.877699700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [
    {
     "data": {
      "text/plain": "survived\n0    650\n1    334\nName: count, dtype: int64"
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train.value_counts() #没存活的是650，存活的是334"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:42.153449900Z",
     "start_time": "2024-07-12T06:58:41.902676100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "data": {
      "text/plain": "sex\nmale      643\nfemale    341\nName: count, dtype: int64"
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_train.loc[:,'sex'].value_counts()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:42.193647900Z",
     "start_time": "2024-07-12T06:58:41.928987400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [
    {
     "data": {
      "text/plain": "0.6744868035190615"
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "230/(230+111)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:42.194648900Z",
     "start_time": "2024-07-12T06:58:41.967259100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "data": {
      "text/plain": "     pclass        age     sex\n598     2nd  30.000000    male\n246     1st  62.000000    male\n905     3rd  31.194181  female\n300     1st  31.194181  female\n509     2nd  64.000000    male\n...     ...        ...     ...\n360     2nd  31.194181    male\n709     3rd  28.000000    male\n439     2nd  34.000000    male\n174     1st  46.000000    male\n1146    3rd  31.194181    male\n\n[984 rows x 3 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>pclass</th>\n      <th>age</th>\n      <th>sex</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>598</th>\n      <td>2nd</td>\n      <td>30.000000</td>\n      <td>male</td>\n    </tr>\n    <tr>\n      <th>246</th>\n      <td>1st</td>\n      <td>62.000000</td>\n      <td>male</td>\n    </tr>\n    <tr>\n      <th>905</th>\n      <td>3rd</td>\n      <td>31.194181</td>\n      <td>female</td>\n    </tr>\n    <tr>\n      <th>300</th>\n      <td>1st</td>\n      <td>31.194181</td>\n      <td>female</td>\n    </tr>\n    <tr>\n      <th>509</th>\n      <td>2nd</td>\n      <td>64.000000</td>\n      <td>male</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>360</th>\n      <td>2nd</td>\n      <td>31.194181</td>\n      <td>male</td>\n    </tr>\n    <tr>\n      <th>709</th>\n      <td>3rd</td>\n      <td>28.000000</td>\n      <td>male</td>\n    </tr>\n    <tr>\n      <th>439</th>\n      <td>2nd</td>\n      <td>34.000000</td>\n      <td>male</td>\n    </tr>\n    <tr>\n      <th>174</th>\n      <td>1st</td>\n      <td>46.000000</td>\n      <td>male</td>\n    </tr>\n    <tr>\n      <th>1146</th>\n      <td>3rd</td>\n      <td>31.194181</td>\n      <td>male</td>\n    </tr>\n  </tbody>\n</table>\n<p>984 rows × 3 columns</p>\n</div>"
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#查看未存活的人的数量\n",
    "x_train"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:42.240033700Z",
     "start_time": "2024-07-12T06:58:41.974694600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "outputs": [
    {
     "data": {
      "text/plain": "[{'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 62.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 64.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 24.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 21.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 23.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 44.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 37.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 6.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 41.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 30.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 25.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 24.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 57.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 25.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 36.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 51.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 43.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 16.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 19.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 13.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 45.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 36.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 22.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 30.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 16.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 47.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 20.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 57.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 58.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 30.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 61.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 38.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 27.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 35.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 58.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 40.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 32.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 21.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 54.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 19.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 38.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 39.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 52.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 60.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 11.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 21.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 45.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 18.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 28.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 19.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 21.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 21.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 65.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 28.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 55.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 22.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 36.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 45.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 24.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 20.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 24.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 15.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 26.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 45.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 35.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 22.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 48.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 48.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 30.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 8.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 21.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 27.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 45.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 25.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 18.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 5.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 25.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 39.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 19.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 36.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 33.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 9.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 26.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 23.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 17.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 36.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 58.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 12.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 23.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 28.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 18.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 36.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 32.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 37.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 25.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 49.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 18.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 44.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 17.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 23.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 32.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 26.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 52.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 28.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 40.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 34.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 27.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 20.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 22.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 40.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 33.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 18.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 37.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 24.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 15.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 28.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 21.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 30.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 20.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 44.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 36.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 39.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 13.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 36.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 12.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 2.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 26.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 27.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 64.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 40.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 42.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 3.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 5.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 22.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 36.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 33.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 45.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 26.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 20.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 18.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 22.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 54.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 11.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 49.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 39.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 22.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 32.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 45.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 10.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 36.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 18.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 18.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 22.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 20.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 44.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 38.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 27.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 36.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 20.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 6.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 16.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 0.3333, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 25.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 18.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 21.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 17.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 55.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 21.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 23.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 40.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 48.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 33.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 49.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 47.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 36.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 48.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 45.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 43.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 52.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 28.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 39.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 9.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 34.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 23.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 49.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 27.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 59.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 28.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 41.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 18.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 27.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 33.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 39.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 8.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 43.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 44.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 30.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 36.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 25.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 26.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 26.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 32.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 18.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 61.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 29.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 29.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 20.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 52.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 42.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 2.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 18.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 25.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 17.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 15.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 19.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 49.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 45.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 20.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 3.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 28.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 37.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 57.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 24.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 30.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 54.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 3.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 24.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 28.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 24.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 25.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 17.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 45.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 48.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 23.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 49.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 0.1667, 'sex': 'female'},\n {'pclass': '2nd', 'age': 8.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 35.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 34.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 23.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 33.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 7.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 27.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 18.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 50.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 39.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 50.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 26.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 46.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 35.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 25.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 30.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 24.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 17.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 27.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 33.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 60.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 58.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 20.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 33.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 38.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 30.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 21.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 54.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 63.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 0.9167, 'sex': 'male'},\n {'pclass': '3rd', 'age': 11.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 21.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 19.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 24.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 43.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 2.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 25.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 45.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 26.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 56.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 19.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 19.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 4.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 45.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 22.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 64.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 32.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 21.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 17.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 55.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 34.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 43.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 17.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 51.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 35.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 22.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 24.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 21.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 26.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 26.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 27.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 53.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 40.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 41.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 36.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 69.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 24.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 28.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 29.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 24.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 49.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 22.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 26.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 48.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 47.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 24.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 32.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 53.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 45.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 67.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 2.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 32.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 2.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 28.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 35.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 28.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 6.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 50.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 36.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 26.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 56.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 19.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 48.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 1.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 27.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 16.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 21.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 21.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 1.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 30.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 16.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 25.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 4.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 30.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 23.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 16.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 36.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 23.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 40.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 58.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 60.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 32.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 39.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 18.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 16.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 18.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 25.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 27.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 42.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 38.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 32.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 20.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 13.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 32.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 45.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 18.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 29.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 20.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 40.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 32.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 32.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 23.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 3.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 35.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 37.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 47.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 21.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 22.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 22.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 25.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 48.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 24.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 25.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 45.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 9.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 59.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 19.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 19.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 42.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 34.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 42.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 29.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 38.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 33.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 19.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 41.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 24.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 34.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 33.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 5.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 18.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 42.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 14.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 29.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 30.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 48.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 18.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 35.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 20.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 42.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 17.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 24.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 71.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 29.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 23.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 4.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 30.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 22.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 19.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 30.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 40.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 25.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 6.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 50.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '1st', 'age': 71.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 9.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 23.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 28.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 53.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 71.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 46.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 49.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 1.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 46.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 37.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 34.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 22.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 19.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '1st', 'age': 46.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 58.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 22.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 45.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 35.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 41.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 46.0, 'sex': 'female'},\n {'pclass': '1st', 'age': 36.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 24.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 44.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 57.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 9.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 23.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 24.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 47.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 50.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 50.0, 'sex': 'female'},\n {'pclass': '2nd', 'age': 34.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 38.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 22.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 18.0, 'sex': 'female'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n {'pclass': '3rd', 'age': 28.0, 'sex': 'male'},\n {'pclass': '2nd', 'age': 34.0, 'sex': 'male'},\n {'pclass': '1st', 'age': 46.0, 'sex': 'male'},\n {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'}]"
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_train.to_dict(orient=\"records\") #把df变为字典，样本变为一个一个的字典，字典中列名变为键"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:42.442426900Z",
     "start_time": "2024-07-12T06:58:42.003955600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n",
      "['age' 'pclass=1st' 'pclass=2nd' 'pclass=3rd' 'sex=female' 'sex=male']\n",
      "--------------------------------------------------\n",
      "[[30.          0.          1.          0.          0.          1.        ]\n",
      " [62.          1.          0.          0.          0.          1.        ]\n",
      " [31.19418104  0.          0.          1.          1.          0.        ]\n",
      " ...\n",
      " [34.          0.          1.          0.          0.          1.        ]\n",
      " [46.          1.          0.          0.          0.          1.        ]\n",
      " [31.19418104  0.          0.          1.          0.          1.        ]]\n"
     ]
    }
   ],
   "source": [
    "# 进行处理（特征工程）特征-》类别-》one_hot编码\n",
    "dict = DictVectorizer(sparse=False)\n",
    "\n",
    "# 这一步是对字典进行特征抽取,to_dict可以把df变为字典，records代表列名变为键\n",
    "x_train = dict.fit_transform(x_train.to_dict(orient=\"records\"))\n",
    "print(type(x_train))\n",
    "print(dict.get_feature_names_out())\n",
    "print('-' * 50)\n",
    "x_test = dict.transform(x_test.to_dict(orient=\"records\"))\n",
    "print(x_train)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:42.525396700Z",
     "start_time": "2024-07-12T06:58:42.129497700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "预测的准确率： 0.8145896656534954\n"
     ]
    }
   ],
   "source": [
    "# 用决策树进行预测，修改max_depth试试,修改criterion为entropy\n",
    "#树过于复杂，就会产生过拟合\n",
    "dec = DecisionTreeClassifier()\n",
    "\n",
    "#训练\n",
    "dec.fit(x_train, y_train)\n",
    "\n",
    "# 预测准确率\n",
    "print(\"预测的准确率：\", dec.score(x_test, y_test))\n",
    "\n",
    "# 导出决策树的结构\n",
    "export_graphviz(dec, out_file=\"tree.dot\",\n",
    "                feature_names=['age', 'pclass=1st', 'pclass=2nd', 'pclass=3rd', 'female', 'male'])\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T07:09:16.207707500Z",
     "start_time": "2024-07-12T07:09:16.168963800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "预测的准确率： 0.8206686930091185\n"
     ]
    }
   ],
   "source": [
    "#调整决策树的参数\n",
    "# 分割数据集到训练集合测试集\n",
    "x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=4)\n",
    "# 进行处理（特征工程）特征-》类别-》one_hot编码\n",
    "dict = DictVectorizer(sparse=False)\n",
    "\n",
    "# 这一步是对字典进行特征抽取\n",
    "x_train = dict.fit_transform(x_train.to_dict(orient=\"records\"))\n",
    "x_test = dict.transform(x_test.to_dict(orient=\"records\"))\n",
    "\n",
    "# print(x_train)\n",
    "# # 用决策树进行预测，修改max_depth为10，发现提升了,min_impurity_decrease带来的增益要大于0.01才会进行划分\n",
    "dec = DecisionTreeClassifier(max_depth=7,min_impurity_decrease=0.01,min_samples_split=20)\n",
    "\n",
    "dec.fit(x_train, y_train)\n",
    "#\n",
    "# # 预测准确率\n",
    "print(\"预测的准确率：\", dec.score(x_test, y_test))\n",
    "#\n",
    "# # 导出决策树的结构\n",
    "export_graphviz(dec, out_file=\"tree1.dot\",\n",
    "                feature_names=dict.get_feature_names_out())"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:42.706529800Z",
     "start_time": "2024-07-12T06:58:42.176661600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "outputs": [
    {
     "data": {
      "text/plain": "(984,)"
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train.shape"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:42.707530Z",
     "start_time": "2024-07-12T06:58:42.220046100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "outputs": [],
   "source": [
    "x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=4)\n",
    "# 进行处理（特征工程）特征-》类别-》one_hot编码\n",
    "dict = DictVectorizer(sparse=False)\n",
    "\n",
    "# 这一步是对字典进行特征抽取\n",
    "x_train = dict.fit_transform(x_train.to_dict(orient=\"records\"))\n",
    "x_test = dict.transform(x_test.to_dict(orient=\"records\"))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-12T06:58:42.708529700Z",
     "start_time": "2024-07-12T06:58:42.227042800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "准确率： 0.8328267477203647\n",
      "查看选择的参数模型： {'max_depth': 3, 'n_estimators': 1500}\n",
      "选择最好的模型是： RandomForestClassifier(max_depth=3, n_estimators=1500, n_jobs=-1)\n"
     ]
    }
   ],
   "source": [
    "# 随机森林进行预测 （超参数调优），n_jobs充分利用多核的一个参数\n",
    "rf = RandomForestClassifier(n_jobs=-1)\n",
    "# 120, 200, 300, 500, 800, 1200,n_estimators森林中决策树的数目，也就是分类器的数目\n",
    "# max_samples  是最大样本数\n",
    "#bagging类型\n",
    "param = {\"n_estimators\": [1500,2000, 5000], \"max_depth\": [2, 3, 5, 8, 15, 25]}\n",
    "\n",
    "# 网格搜索与交叉验证\n",
    "gc = GridSearchCV(rf, param_grid=param, cv=3)\n",
    "\n",
    "gc.fit(x_train, y_train)\n",
    "\n",
    "print(\"准确率：\", gc.score(x_test, y_test))\n",
    "\n",
    "print(\"查看选择的参数模型：\", gc.best_params_)\n",
    "\n",
    "print(\"选择最好的模型是：\", gc.best_estimator_)\n",
    "\n",
    "# print(\"每个超参数每次交叉验证的结果：\", gc.cv_results_)\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-07-12T07:22:25.727560800Z",
     "start_time": "2024-07-12T07:17:56.174742300Z"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
